package com.ujs.edu.medicine.dao;

import com.ujs.edu.medicine.dataobject.TableMS;
import java.util.List;

import com.ujs.edu.medicine.dataobject.YunjiayiMedicine;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface TableMSMapper {
    @Delete({
        "delete from table_m_s",
        "where tid = #{tid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer tid);

    @Insert({
        "insert into table_m_s (tid, shopId, ",
        "medicineId)",
        "values (#{tid,jdbcType=INTEGER}, #{shopid,jdbcType=INTEGER}, ",
        "#{medicineid,jdbcType=INTEGER})"
    })
    int insert(TableMS record);

    @Select({
        "select",
        "tid, shopId, medicineId",
        "from table_m_s",
        "where tid = #{tid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="tid", property="tid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="shopId", property="shopid", jdbcType=JdbcType.INTEGER),
        @Result(column="medicineId", property="medicineid", jdbcType=JdbcType.INTEGER)
    })
    TableMS selectByPrimaryKey(Integer tid);

    @Select({
        "select",
        "tid, shopId, medicineId",
        "from table_m_s"
    })
    @Results(id = "tableMap",value = {
        @Result(column="tid", property="tid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="shopId", property="shopid", jdbcType=JdbcType.INTEGER),
        @Result(column="medicineId", property="medicineid", jdbcType=JdbcType.INTEGER)
    })
    List<TableMS> selectAll();


    @Select("select * from table_m_s where shopId=#{shopId}")
    @Results({
            @Result(column="tid", property="tid", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="shopId", property="shopid", jdbcType=JdbcType.INTEGER),
            @Result(column="medicineId", property="medicineid", jdbcType=JdbcType.INTEGER),
            @Result(property = "medicine",column = "medicineId",many = @Many(select = "com.ujs.edu.medicine.dao.YunjiayiMedicineMapper.selectByPrimaryKey",fetchType = FetchType.LAZY))
    })
    List<TableMS> getMedicinesInShop(@Param("shopId")Integer shopId);

    @Update({
        "update table_m_s",
        "set shopId = #{shopid,jdbcType=INTEGER},",
          "medicineId = #{medicineid,jdbcType=INTEGER}",
        "where tid = #{tid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(TableMS record);
}